<template>
  <el-main>
    <el-row class="body-card">
      <h3 style="cursor: pointer">查找用户</h3>
      <Divider/>
      <el-row>
  <el-input  v-model="searchtext_id" placeholder="请输入用户id" style="width: 400px;">
            <el-button slot="append" type="submit" class="search-submit" @click="searchuser()">查找</el-button>	 
          </el-input> 
      </el-row> 
	  <el-row style="margin-top:50px">
		   <el-card :body-style="{ padding: '0px' }">
		    <div style="padding: 14px;">
        <span>  {{ searchuser_items.username}} (用户id: {{ searchuser_items.id}})</span>
        <div class="bottom clearfix">  
          <el-button type="text" @click="handleFriendApply(searchuser_items.id)">申请好友</el-button>
        </div> 
      </div> 
    </el-card> 
      </el-row>
        
    </el-row>
  </el-main>
</template>
<script>
 import {
  searchuserServer,
  friendServer, 
} from "../../api/friend";
  export default {
    name: "friendsearchmenu",
    data() {
      return {
        dialogFormVisible: false,
        dialogTypes: 0,
        formLabelWidth: '100px',
		searchtext_id:"", 
        searchuser_items: {
	},
        formData: {
          id: 123,
          name: "张三",
          role: 'StandardUser'
        }
      };
    }, 
    methods: {
      searchuser(){  
        searchuserServer("get",{ params: { searchtext_id: this.searchtext_id }  }
        ).then(
          suc => {
            const { code, data, message } = suc.data;
            if (code) {
			this.searchuser_items = data;
			console.log(this.searchuser_items);
             } else {
              this.$message({
                type: "error",
                message
              });
            }
          },
          err => {
            this.$message({
              type: "error",
              message: err.message
            });
          }
        );
      },
	  	handleFriendApply(applyid){
	 if (!!applyid) { 
        this.$confirm("是否向该用户提出好友申请?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
              friendServer("post", {
          applyid:this.applyid,
        }).then(
          suc => {
            const { code,  message } = suc.data;
            if (code) { 
			      this.$message({
                  type: "success",
                  message
          });
             } else {
              this.$message({
                type: "error",
                message
              });
            }
          },
          err => {
            this.$message({
              type: "error",
              message: err.message
            });
          }
        );
        });
      }
	},
  
    }
  };
</script>

<style lang="less">

</style>
